<jsp:directive.page contentType="text/html;charset=UTF-8" />
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="../../WEB-INF/c.tld" prefix="c" %>

<div class="main">
	<div class="container">
	
	<c:if test="${error != null}">
			<div class="alert alert-error">
				<bean:message key="${error }" />
    		</div>
	</c:if>
		
	<html:form action="${action }" method="post" onsubmit="return validateRelaiForm(this);" styleClass="form-horizontal">
		<fieldset>
			<legend><bean:message key="relai.Form" /></legend>
				<html:hidden property="idRelai" value="${relai.idRelai }"/>
				<div class="control-group">
					<label class="control-label" for="numeroRelai"><bean:message key="relai.Numero" /></label>
					<div class="controls">
						<html:text property="numeroRelai" size="16" maxlength="16" readonly="true" styleId="numrelai" value="${relai.numeroRelai }"/>
						<div class="icon-refresh" id="generate"></div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="libelle"><bean:message key="relai.Name" /></label>
					<div class="controls">
						<html:text property="libelle" size="16" maxlength="16" value="${relai.nom }"/>
					</div>
				</div>
				<div class="control-group">
						<label class="control-label" for="adresse"><bean:message key="relai.Adresse" /></label>
						<div class="controls">
							<html:text property="adresse" size="16" maxlength="16" value="${relai.adresse.adresse }"/>
					</div>
				</div>
				<div class="control-group">
						<label class="control-label" for="complementAdresse"><bean:message key="relai.ComplementAdresse" /></label>
						<div class="controls">
							<html:text property="complementAdresse" size="16" maxlength="16" value="${relai.adresse.complementsAdresse }"/>
					</div>
				</div>
				<div class="control-group">
						<label class="control-label" for="codePostal"><bean:message key="relai.CodePostal" /></label>
						<div class="controls">
							<html:text property="codePostal" size="16" maxlength="16" value="${relai.adresse.codePostal }"/>
					</div>
				</div>
				<div class="control-group">
						<label class="control-label" for="ville"><bean:message key="relai.Ville" /></label>
						<div class="controls">
							<html:text property="ville" size="16" maxlength="16" value="${relai.adresse.ville }" />
					</div>
				</div>
				<div class="form-actions">
					<button class="btn btn-primary" type="submit"><bean:message key="general.valider" /></button>
				</div>
		</fieldset>
		<html:javascript formName="RelaiForm" />
	</html:form>
</div>
</div>

<script type="text/javascript">

$('generate').observe('click',function(evt){
	var url = "<%= request.getContextPath() %>/generer-numrelai.do";
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var json = transport.responseText.evalJSON();
	    $('numrelai').setValue(json.num);
	}
  });
});
</script>

	